package homeworkday03;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

/**
 * 将当前目录下的所有obj文件获取到，并进行
 * 反序列化后输出每个用户的信息(直接输出反序
 * 列化后的User对象即可)
 * @author Xiloer
 *
 */
public class Ois {
    public static void main(String[] args) {
        File file = new File(".");
        File[] files = file.listFiles(f->f.getName().contains(".obj"));
        for (int i = 0; i < files.length; i++) {
            try(ObjectInputStream ois = new ObjectInputStream(
                    new FileInputStream(files[i]));) {
                User user = (User) ois.readObject();
                System.out.println(user);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }

    }
}
